<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<body>
	<script type="text/javascript">
		$(function() {
			$("#user_datagrid").datagrid({
				width : 'auto',
				height : 'auto',
				fit:true,
				pageSize : 20,
				pageList : [ 5, 10, 20 ],
				nowrap : false,
				striped : true,
				//singleSelect : true,
				url : "user/datagrid.action",
				loadMsg : "数据正在加载……",
				pagination : true,
				rownumbers : true,
				columns : [ [ 
				    {field:"ck",checkbox:true} , 
				    {field : 'userNo',title : '编号',align : 'center',width : '100'},
				    {field : 'loginName',title : '账号',align : 'center',width : '100'},
					{field : 'name',title : '姓名',align : 'center',width : '100'},
					{field : 'age',title : '年龄',align : 'center',width : '100'},
					{field : 'sex',title : '性别',align : 'center',width : '100', formatter:function(val){
						return findValueByKey(sexenums, val);
					}},
					{field : 'orgName',title : '部门',align : 'center',width : '100'},
					{field : 'job',title : '职务',align : 'center',width : '100'},
					{field : 'tel',title : '电话',align : 'center',width : '100'},
					{field : 'email',title : '邮箱',align : 'center',width : '100'},
					{field : 'birthday',title : '生日',align : 'center',width : '100'}
				] ],
				toolbar:[{
					text:"新增",
					handler:function() {
						$("#user_add_dialog").dialog({
							title:"新增用户",
							width:600,
						    height: 420,
						    closed: false,
						    cache: false,
						    href: 'platform/user/add.jsp',
						    modal: true,
						    resizable:true,
						    buttons:[{
								text:'保存',
								handler:function(){
									var data = $("#user_form").serialize();
									$.ajax({
										url:"user/add.action",
										type:"post",
										data:data,
										dataType:"json",
										success:function(data) {
											$.messager.alert("提示", data.msg, "info", function() {
												if(data.isSuccess) {
													$("#user_add_dialog").dialog("close");
													$("#user_datagrid").datagrid("load");
												}
											});
										}
									});
								}
							},{
								text:'关闭',
								handler:function(){
									$("#user_add_dialog").dialog("close");
								}
							}]
						});
					}
				},'-',{
					text:"删除",
					handler:function() {
						var checks = $("#user_datagrid").datagrid("getChecked");
						var ids = "";
						var len = checks.length;
						if(len==0) $.messager.alert("提示", "请选择要删除的记录！！");
						else {
							$.each(checks, function(i, n){
								ids+=n.id+(i<len-1?",":"");
							}); 
							$.ajax({
								url:"user/del.action",
								type:"post",
								data:{ids:ids},
								dataType:"json",
								success:function(data) {
									$.messager.alert("提示", data.msg, "info", function() {
										if(data.isSuccess) {
											$("#user_datagrid").datagrid("load");
										}
									});
								}
							});
						}
					}
				},'-',{
					text:"重置密码",
					handler:function() {
						alert("重置密码了");
					}
				}]
			});
		});
		
	</script>
	<table id="user_datagrid"></table>
	<div id="user_add_dialog"></div>
	<div id="user_role_dialog"></div>
</body>